package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.BaseHouseInfo;
import com.softer.wxzj.entity.HouseAndOwner;
import com.softer.wxzj.entity.RefPayInfo;
import com.softer.wxzj.entity.RefReq;
import com.softer.wxzj.service.RefReqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * RefReqController class
 *
 * @author wxr
 * @date 2019/7/1
 */
@RestController
@RequestMapping("/refReq")
@Slf4j
public class RefReqController {

    @Autowired
    RefReqService refReqService;

    /**
     * 根据业主id查询退款基本信息
     *
     * @param ownerId 业主id
     * @return 结果
     */
    @PostMapping("/getRefInfoByOwnerId")
    @LogRecord(description = "根据业主id查询退款基本信息", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public BaseHouseInfo getRefInfoByOwnerId(@RequestParam("ownerId") String ownerId, @RequestParam("refType") String refType) {
        BaseHouseInfo baseHouseInfo = refReqService.getRefInfoByOwnerId(ownerId, refType);
        return baseHouseInfo;
    }

    @RequestMapping("/save")
    @LogRecord(description = "资金退款保存", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public CommonResult save(RefReq refReq) {
        log.info("资金退款保存,操作人:{}", ShiroUserUtil.getUser().getOperName());
        return refReqService.save(refReq);
    }

    @RequestMapping("/refSingleSubmit")
    @LogRecord(description = "资金退款提交审批", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public CommonResult refSingleSubmit(String refId, String arcType, String accNo) {
        log.info("资金退款提交审批,操作人:{}", ShiroUserUtil.getUser().getOperName());
        return refReqService.refSingleSubmit(refId, arcType, accNo);
    }


    @RequestMapping("/getPartRefundList")
    @LogRecord(description = "部分退款查询列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> getPartRefundList(Page page, RefReq refReq) {
        return refReqService.getPartRefundList(page, refReq);
    }

    @RequestMapping("/refRevoke")
    @LogRecord(description = "退款撤销", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public CommonResult refRevoke(@RequestParam("id") String id) {
        log.info("退款撤销,操作人:{}", ShiroUserUtil.getUserName());
        return refReqService.refRevoke(id);
    }

    @RequestMapping("/refBatchSubmit")
    @LogRecord(description = "批量退款申请", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public CommonResult refBatchSubmit(@RequestBody List<RefReq> list) {
        log.info("批量退款申请,操作人:{}", ShiroUserUtil.getUserName());
        return refReqService.refBatchSubmit(list);
    }

    /**
     * 凭证打印列表
     *
     * @param page
     * @param houseAndOwner
     * @return
     */
    @RequestMapping("/certificatePrinting")
    @LogRecord(description = "凭证打印列表", operationUnit = LogOperationUnit.CERTIFICATE_PRINGTIN, operationType = LogOperationType.SELECT)
    public PageInfo<HouseAndOwner> selectReqRefState(Page page, HouseAndOwner houseAndOwner) {
        return refReqService.selectReqRefState(page, houseAndOwner);
    }

    @RequestMapping("/getBatchRefundList")
    @LogRecord(description = "批量退款查询列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> getBatchRefundList(Page page, RefReq refReq) {
        return refReqService.getBatchRefundList(page, refReq);
    }

    @RequestMapping("/getAuditList")
    @LogRecord(description = "退款待审列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> getAuditList(Page page, RefReq refReq) {
        return refReqService.getAuditList(page, refReq);
    }

    /**
     * 凭证冻结撤销列表
     *
     * @param page
     * @param refReq
     * @return
     */
    @RequestMapping("/documentFreezingRevocatio")
    @LogRecord(description = "凭证冻结撤销列表", operationUnit = LogOperationUnit.CERTIFICATE_PRINGTIN, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> documentFreezingRevocatio(Page page, RefReq refReq) {
        return refReqService.documentFreezingRevocatio(page, refReq);
    }

    @RequestMapping("/getRefInfo")
    @LogRecord(description = "查询退框详情（退款审核详情页面）", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public RefReq getRefInfo(@RequestParam("id") String id) {
        return refReqService.getRefInfo(id);
    }

    @RequestMapping("/audit")
    @LogRecord(description = "退款/销户审批", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public CommonResult audit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        log.info("批量退款申请,操作人:{},状态:{},意见:{},id:{}", ShiroUserUtil.getUserName(), mark, opinion, id);
        return refReqService.audit(id, opinion, mark);
    }

    @RequestMapping("/getRefList")
    @LogRecord(description = "退款在途查询列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> getRefList(Page page, RefReq refReq) {
        return refReqService.getRefList(page, refReq);
    }

    @RequestMapping("/selectVaildDateById")
    @LogRecord(description = "退款日期", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.INSERT)
    public RefReq selectVaildDateById(String id) {
        return refReqService.selectVaildDateById(id);
    }

    /**
     * 批量凭证打印列表
     *
     * @param page
     * @param refReq
     * @return
     */
    @RequestMapping("/selectAllReqRefState")
    @LogRecord(description = "批量凭证打印列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> selectAllReqRefState(Page page, RefReq refReq) {
        return refReqService.selectAllReqRefState(page, refReq);
    }

    @RequestMapping("/getCancelRevokeList")
    @LogRecord(description = "退款撤销列表", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefReq> getCancelRevokeList(Page page, RefReq refReq) {
        log.info("资金撤销列表,操作人:{}", ShiroUserUtil.getUserName());
        return refReqService.getCancelRevokeList(page, refReq);
    }

    @RequestMapping("/refCancel")
    @LogRecord(description = "退款撤销（审核通过，未记账）", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult refCancel(@RequestParam("id") String id) {
        log.info("批量退款申请,操作人:{},id:{}", ShiroUserUtil.getUserName(), id);
        return refReqService.refCancel(id);
    }

    /**
     * 资金退款，看是否可以退款
     */
    @RequestMapping("/drawback")
    @LogRecord(description = "资金部分退款，看是否可以退款", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public CommonResult drawback(String ownerId, String refType) {
        return refReqService.drawback(ownerId, refType);
    }

    /**
     * 资金退款，看是否可以退款
     */
    @RequestMapping("/selectpayAmount")
    @LogRecord(description = "资金退款全额退款销户，看是否可以退款", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public CommonResult selectpayAmount(String ownerId, String refType) {
        return refReqService.selectpayAmount(ownerId, refType);
    }

    @RequestMapping("/getRefPayInfoByReqId")
    @LogRecord(description = "部分退款退款明细查询", operationUnit = LogOperationUnit.REF_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<RefPayInfo> getRefPayInfoByReqId(Page page, String id, String fuzzy) {
        return refReqService.getRefPayInfoByReqId(id, page, fuzzy);
    }

}
